package com.shen.module_room.migration

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

/**
 * //在表device_init中添加TEXT字段mimc
 * database.execSQL("ALTER TABLE device_init ADD COLUMN mimc TEXT")
 *
 * // 在表device_init中添加TEXT字段appId
 * database.execSQL(("ALTER TABLE device_init ADD COLUMN appId TEXT"))
 *
 * // 创建新表connect_prod并添加对应的字段
 * // PRIMARY KEY(id)将id设置为主键，NOT NULL设置对应的键不能为空
 * database.execSQL(
 *     "CREATE TABLE connect_prod(icon TEXT,local_file_path TEXT,action_res TEXT,url TEXT,idx TEXT,thumb_image_url TEXT," +
 *             "title TEXT,name TEXT,online TEXT,down TEXT,type TEXT,down_load_complete INTEGER NOT NULL,id TEXT NOT NULL,res TEXT,PRIMARY KEY(id))"
 * )
 *
 *
 * // INTEGER   NOT NULL 设置默认值
 * database.execSQL("ALTER TABLE user ADD COLUMN birthday INTEGER NOT NULL DEFAULT 23 ")
 */
object MigrationObj {
    val MIGRATION_1_2: Migration = object : Migration(1, 2) {
        override fun migrate(database: SupportSQLiteDatabase) {
            database.execSQL("ALTER TABLE user_info ADD COLUMN head_photo TEXT")
        }
    }

    val MIGRATION_2_3: Migration = object : Migration(2, 3) {
        override fun migrate(database: SupportSQLiteDatabase) {
            database.execSQL("ALTER TABLE user_info ADD COLUMN is_login INTEGER NOT NULL DEFAULT 0")
        }
    }

    val MIGRATION_3_4: Migration = object : Migration(3, 4) {
        override fun migrate(database: SupportSQLiteDatabase) {
            database.execSQL("CREATE TABLE chat_record(id INTEGER NOT NULL,content TEXT NOT NULL DEFAULT '',is_send INTEGER NOT NULL DEFAULT 0,PRIMARY KEY(id))")
        }
    }

}